//定义一个数据
import Vue from 'vue'
import MobileSelect from 'mobile-select'
import qs from 'qs'
import router from '../router'

let system = {
    state:  { //  全局性的变量
        title: '学校信息',
        //学校
        school: {
            school_id:null,
            name: '',//学校名称
            province: 0,//省
            city: 0,//市
            area: 0,//区 县
            address: null,//详细地址
            type: null,//类型 小学1 /初中 2 /高中 3
            category:null,//类别:0=一类,1=二类,2=三类,3=普通,4=重点',
            class:null,//总班数
            total_number: '',//总人数
            textbook_edition:[
                {name: '语文',fraction: ''},
                {name: '数学',fraction: ''},
                {name: '英语',fraction: ''},
                {name: '物理',fraction: ''},
                {name: '化学',fraction: ''},
                {name: '生物',fraction: ''},
                {name: '历史',fraction: ''},
                {name: '地理',fraction: ''},
                {name: '政治',fraction: ''},
                {name: '技术',fraction: ''},
            ],//总班数
            policylist: '',//小升初政策
            is_schoolsdata:2,//是否五四制:1=是,2=否',
            total_score: '',//当地中考科目及总分
            volume: null,//试卷版本
            teaching_order: null,//教学顺序
            bookstore:[]
        },
        //校园书店
        bookstore:{
        	name: '',//书店名称
        	address: '',//书店地址
        	phone: '',//联系方式
        },
        //年级
        grade: {
            school_id: null,//学校ID
            grade_id: 1,//年级ID
            name: '',//年级名称
            total_grade: '',//总班数
            total_number: '',//总人数
            cycle: '',//放假周期
            subject:null,
            revision:'',//选科总复习开始时间
            self_study: 2,//是否晚自习:1=是,2=否',
        },
        gradeEdit: {
            school_id: null,//学校ID
            grade_id: null,//年级ID
            name: '',//年级名称
            total_grade: '',//总班数
            total_number: '',//总人数
            cycle: '',//放假周期
            revision:'',//选科总复习开始时间
            self_study: null,//是否晚自习:1=是,2=否',
        },
        //班级表
        classes: {
            school_id: null,//学校ID
            grade_id: null,//年级ID
            class_id: null,//班级ID
            name:'',//班级名称
            class_type:1,//班级类型
            total_number: '',//班级人数
        },
        classesEdit: {
            school_id: null,//学校ID
            grade_id: null,//年级ID
            class_id: null,//班级ID
            name:'',//班级名称
            class_type:1,//班级类型
            total_number: '',//班级人数
        },
        //人员信息表
        personnel: {
            school_id: null,//学校ID
            grade_id: null,//年级ID
            class_id: null,//班级ID
            role:null, //角色
            name:'',//姓名
            sex:'',//性别
            age:'',//年龄
            phone:'',//手机
            subject: null,//所教学科
            is_class:2,//是否坐班
            characteristic:'',//特点
            like:'',//喜好
        },
        principal: false,  //校长  假可添加  真不可添加
        schoolArray: [],
        gradeArray: [],
        gradeNumber: 1,
        classArray: [],
        classNumber: 1,
        personnelArray: [],
        provincedata: null,
        provinceTitle: '请选择',
        provinceIndex: [0,0],
        citydata: [
            {name:'城市',value: 0}
        ],
        areadata: [
            {name:'区/县',value: 0}
        ],
        typedata: [
            {id: 1,'name': '小学'},
            {id: 2,'name': '初中'},
            {id: 3,'name': '高中'},
        ],
        categorydata:[
            {id: 0,'name': '一类'},
            {id: 1,'name': '二类'},
            {id: 2,'name': '三类'},
            {id: 3,'name': '普通'},
            {id: 4,'name': '重点'},
        ],
//      policylistdata:[  //学校政策:1=分招,2=统招,3=名额,4=其他
//          {id: 1,name: '分招'},
//          {id: 2,name: '统招'},
//          {id: 3,name: '名额'},
//          {id: 4,name: '其他'},
//      ],
        self_studydata: [
            {id: 1,name: '是'},
            {id: 2,name: '否'},
        ],
        volumedata: [//试卷版本:1=全国卷,2=北京卷,3=上海卷,4=江苏卷,5=江苏卷',
            {id: 1,name: '全国卷'},
            {id: 2,name: '北京卷'},
            {id: 3,name: '上海卷'},
            {id: 4,name: '江苏卷'},
            {id: 5,name: '江苏卷'},
        ],
        textbook_editiondata: [//教材版本:
            {id: 1,name: '人教版'},
            {id: 2,name: '北师大版'},
            {id: 3,name: '鲁教版'},
            {id: 4,name: '苏教版'},
            {id: 5,name: '粤教版'},
            {id: 6,name: '湘教版'},
        ],
        teaching_orderdata: [ //'教学顺序:1=必修1~5,2=选修1·1~3,3=选修2·1~2',
            {id: 1,name: '必修1~5'},
            {id: 2,name: '选修1·1~3'},
            {id: 3,name: '选修2·1~2'}
        ],
        subjectdata: [
            {id: 1,name: '语文'},
            {id: 2,name: '数学'},
            {id: 3,name: '英语'},
            {id: 4,name: '物理'},
            {id: 5,name: '化学'},
            {id: 6,name: '生物'},
            {id: 7,name: '历史'},
            {id: 8,name: '地理'},
            {id: 9,name: '政治'},
            {id: 10,name: '技术'},
        ],
        content: [
            {id: 1,title: '添加校长',editTitle: '修改校长信息'},
            {id: 2,title: '添加副校长',editTitle: '修改副校长信息'},
            {id: 3,title: '添加教导主任',editTitle: '修改教导主任信息'},
            {id: 4,title: '添加学科备课组长',editTitle: '修改学科备课组长信息'},
            {id: 5,title: '添加年级组长',editTitle: '修改年级组长信息'},
            {id: 6,title: '添加班主任',editTitle: '修改班主任信息'},
            {id: 7,title: '添加任课教师',editTitle: '修改任课教师信息'},
            {id: 8,title: '添加班长',editTitle: '修改班长信息'},
        ],
        grade_content: {
        	title: '添加年级',
        	editTitle: '修改年级信息'
        },
        bookstore_content: {
        	title: '添加书店',
        	editTitle: '修改书店信息'
        },
        classes_content: {
        	title: '添加班级',
        	editTitle: '修改班级信息'
        },
        subject_content: {
        	title: '教材版本'
        },
        roledata: [ //角色:1=校长,2=副校长,3=教导主任,4=学科备课组长,5=年级组长,6=班主任,7=任课教师,8=班长
            {id: 1,name: '校长'},
            {id: 2,name: '副校长'},
            {id: 3,name: '教导主任'},
            {id: 4,name: '学科备课组长'},
            {id: 5,name: '年级组长'},
            {id: 6,name: '班主任'},
            {id: 7,name: '任课教师'},
            {id: 8,name: '班长'},
        ],
        class_typedata:[ //班级类型:1=实验班,2=普通班
            {id: 1,name: '实验班'},
            {id: 2,name: '普通班'}
        ],
    },
    mutations: {
        addProvince (state,province) {
            state.provincedata = province
            var mobileSelect5 = new MobileSelect({
                trigger: '#trigger5',
                title: '学校地址',
                wheels: [
                    {data: state.provincedata}
                ],
                position: state.provinceIndex,
                transitionEnd:function(indexArr, data){   //选中的数据
                },
                callback:function(indexArr, data){  //确定返回的数据
                    state.school.province = data[0].id
                    state.school.city = data[1].id
                    state.school.area = data[2].id
                    state.provinceTitle = data[0].value +' '+ data[1].value +' '+ data[2].value
                    state.provinceIndex = indexArr
                }
            });
        },
        save(state) {
            //判断学校数据是否添加
            //提交数据到服务器
            let school  = {school: state.school, grade: state.gradeArray, class: state.classArray, personnel: state.personnelArray}
            Vue.axios.post('http://oa.fc62.com/api/school/add',qs.stringify(school)).then(response => {
                if(response.data.data == 'success')
                {
                    state.school = {
                        school_id:null,
                        name: '',//学校名称
                        province: 0,//省
                        city: 0,//市
                        area: 0,//区 县
                        address: null,//详细地址
                        type: null,//类型 小学1 /初中 2 /高中 3
                        category:null,//类别:0=一类,1=二类,2=三类,3=普通,4=重点',
                        class:null,//总班数
                        total_number: '',//总人数
                        textbook_edition:[
                            {name: '语文',fraction: ''},
                            {name: '数学',fraction: ''},
                            {name: '英语',fraction: ''},
                            {name: '物理',fraction: ''},
                            {name: '化学',fraction: ''},
                            {name: '生物',fraction: ''},
                            {name: '历史',fraction: ''},
                            {name: '地理',fraction: ''},
                            {name: '政治',fraction: ''},
                            {name: '技术',fraction: ''},
                        ],//总班数
                        policylist: '',//小升初政策
                        is_schoolsdata:2,//是否五四制:1=是,2=否',
                        total_score: '',//当地中考科目及总分
                        volume: null,//试卷版本
                        teaching_order: null,//教学顺序
                        bookstore:[]
                    };
                    state.gradeArray = '';
                    state.classArray = '';
                    state.personnelArray = '';
                    layer.open({content: '添加学校成功', skin: 'msg', time: 2 })
                    router.push('/')
                }
            })
        }
    },
    actions: {
        getProvince (store) {  //调用省市区方法
            Vue.axios.get('http://oa.fc62.com/api/demo/area').then(response => {
                store.commit('addProvince', response.data.data)
            })
        }
    }
}
export default system //导出数据